//
// Created by Jisam on 2024/6/18.
// 20点35分
// 20点45分
#include<bits/stdc++.h>

using namespace  std;
struct node {
    int idx;
    int time;
};
const int manx  =  1e5+5;
node a[manx],b[manx];
int n;

int x,y,c,d;
int ia = 0 ,ib = 0;
bool cmp(node n1 ,node n2){
    return  n1.time < n2.time;
}
int main(){
    cin >> n;

    for(int i = 1 ; i <= n ; i ++){
        cin >> x >> y >> c >> d;
        if (c == 1 && d == 1){
            if(x < y) {
                a[ia].idx = i;
                a[ia].time = x;
                ia ++;
            }else {
                b[ib].idx = i;
                b[ib].time = y;
                ib++;
            }
            continue;
        }
        if (c == 1 && d == 0) {
            a[ia].idx = i;
            a[ia].time = x;
            ia ++;
            continue;
        }
        if (d == 1 && c == 0){
            b[ib].idx = i;
            b[ib].time = y;
            ib++;
            continue;
        }
    }

    sort(a,a +ia ,cmp);

    sort(b,b +ib ,cmp);
    cout << ia << " ";
    for(int i = 0; i < ia ; i ++){cout << a[i].idx  << " ";}

    cout << "\n" << ib << " ";
    for(int i = 0; i < ib ; i ++){cout << b[i].idx  << " ";}

    return  0;
}